const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');
const User = require('./User');
const Video = require('./Video');

const VideoLike = sequelize.define('VideoLike', {
  id: {
    type: DataTypes.INTEGER,
    autoIncrement: true,
    primaryKey: true
  },
  user_id: {
    type: DataTypes.STRING(255),
    allowNull: false,
    references: {
      model: User,
      key: 'id'
    }
  },
  video_id: {
    type: DataTypes.STRING(255),
    allowNull: false,
    references: {
      model: Video,
      key: 'id'
    }
  },
  created_at: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  }
}, {
  tableName: 'video_likes',
  timestamps: false,
  indexes: [
    {
      unique: true,
      fields: ['user_id', 'video_id']
    }
  ]
});

// 关联
VideoLike.belongsTo(User, { foreignKey: 'user_id', onDelete: 'CASCADE' });
VideoLike.belongsTo(Video, { foreignKey: 'video_id', onDelete: 'CASCADE' });

module.exports = VideoLike;